﻿using System;
using System.Collections;
using System.Data;
using CE.Database;

using System.Data.SqlClient;
using System.Data.Common;
/// <summary>
/// Summary description for CMIDB
/// </summary>
/// 
namespace CE.Promotion
{
    public class WorldCupPromotionDB
    {
        public WorldCupPromotionDB()
        {
        }

        public Int64 InsertUpdate(WorldCupPromotion promotiondata)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocWorldCupContestInsertUpdateSingleItem";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@WorldCupUserId", promotiondata.WorldCupUserId);
            _sPara.Add("@Name", promotiondata.Name);
            _sPara.Add("@Email", promotiondata.Email);
            _sPara.Add("@Mobile", promotiondata.Mobile);
            _sPara.Add("@CarYear", promotiondata.CarYear);
            _sPara.Add("@CarMake", promotiondata.CarMake);
            _sPara.Add("@CarModel", promotiondata.CarModel);
            _sPara.Add("@CarMakeModelDesc", promotiondata.CarMakeModelDesc);
            _sPara.Add("@CommencementMonth", promotiondata.CommencementMonth);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public Int64 VerifiedDate(Int64 WorldCupUserId)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocWorldCupVerifiedDateSingleItem";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@WorldCupUserId", WorldCupUserId);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);
            return _result;
        }


        public WorldCupPromotion GetPromotion(Int64 WorldCupUserId)
        {
            WorldCupPromotion _promotion = null;
            MyDatabase _db = new MyDatabase();

            using (DataTable _dt = _db.GetDataTable("SELECT WCUserId,Name,Email,Mobile,CarYear,CarMake,CarModel,CarMakeModelDesc,CommencementMonth FROM tblWorldCupContest WHERE WorldCupUserId=" + WorldCupUserId.ToString()))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _promotion = new WorldCupPromotion();
                    _promotion = FillDataRecord(_dt, 0);
                }
            }
            return _promotion;
        }

        private WorldCupPromotion FillDataRecord(DataTable myDataTable, int RowId)
        {
            WorldCupPromotion myPromotion = new WorldCupPromotion();

            myPromotion.WorldCupUserId = Convert.ToInt16(myDataTable.Rows[RowId]["WCUserId"].ToString());
            myPromotion.Name = myDataTable.Rows[RowId]["Name"].ToString();
            myPromotion.Email = myDataTable.Rows[RowId]["Email"].ToString();
            myPromotion.Mobile = myDataTable.Rows[RowId]["Mobile"].ToString();
            myPromotion.CarYear = Convert.ToInt32(myDataTable.Rows[RowId]["CarYear"].ToString());
            myPromotion.CarMake = myDataTable.Rows[RowId]["CarMake"].ToString();
            myPromotion.CarModel = myDataTable.Rows[RowId]["CarModel"].ToString();
            myPromotion.CarMakeModelDesc = myDataTable.Rows[RowId]["CarMakeModelDesc"].ToString();
            myPromotion.CommencementMonth = Convert.ToInt64(myDataTable.Rows[RowId]["CommencementMonth"].ToString());
            return myPromotion;
        }


    }
}
